import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class LimitReviewPage(BasePage):

    def __init__(self, driver):
        super().__init__(driver)
        # 定位的元素
        self.loan_manager = (By.XPATH, '/html/body/div[1]/div[2]/ul/li[2]/a')
        self.limit_manager = (By.XPATH, '//*[@id="sidebar"]/ul/li[5]/a/span')
        self.limit_review = (By.XPATH, '//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a')
        self.search_user = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[1]/div/input')
        self.search_btn = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[3]/input')
        # frame元素
        self.frame = (By.ID, 'iframe_box')

        # 结果记录
        self.record = (By.XPATH, '/html/body/div[2]/div[3]/table/tbody/tr[1]')
        # 审核按钮
        self.review_btn = (By.XPATH, '/html/body/div[2]/div[2]/ul/li[1]/a/span')
        # 通过按钮
        self.frame1 = (By.CSS_SELECTOR, '#xubox_iframe1')
        self.pass_btn = (By.CSS_SELECTOR, '.ace.ng-pristine.ng-untouched.ng-valid')
        # 审核备注
        self.review_detail = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea')
        # 验证码
        self.code = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[7]/td[2]/div/ul/li[1]/input')
        # 保存按钮
        self.save_btn = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]')

    # 菜单操作定义一个方法
    def menu_manager(self):
        """进入额度审核菜单"""
        self.base_click(self.loan_manager)
        self.base_click(self.limit_manager)
        self.base_click(self.limit_review)

    # 审核定义另一个方法
    def limit_review_page(self, user):
        """额度审核列表页"""
        # 切换frame
        self.base_switch_frame(self.frame)
        # 输入用户名
        self.base_input(self.search_user, user)
        # 点击搜索按钮
        self.base_click(self.search_btn)
        # 选择结果记录
        time.sleep(1)
        self.base_click(self.record)
        # 点击审核按钮
        self.base_click(self.review_btn)

    def review_operate(self, notes="审核通过啦", code="8888"):
        """额度审核页操作"""
        # 切换frame
        self.base_switch_frame(self.frame1)
        # 点击通过按钮
        self.base_click(self.pass_btn)
        # 输入审核备注
        self.base_input(self.review_detail, notes)
        # 输入验证码
        self.base_input(self.code, code)
        # 点击保存按钮
        self.base_click(self.save_btn)

